import React, {useState} from "react";

export default class App extends React.Component {
    state = {
        username: '',
        password: '',
        age: ''

    }
    // 柯里化实现受控组件
    saveForm = (dataType) => {
        return (e) => {
            this.setState(
                {
                    [dataType]: e.target.value
                }
            )
        }
    }
    // 不使用柯里化实现受控组件
    saveForm2 = (dataType,val) =>{
        this.setState({
            [dataType]: val
        })
    }


    render() {
        return (
            <div>
                <form action="">
                    <input type='text' name='username' onChange={this.saveForm('username')}/>
                    <input type='text' name='password' onChange={this.saveForm('password')}/>
                    <input type='text' name='age' onChange={(event)=>{
                        this.saveForm2('age',event.target.value)
                    }}/>

                </form>
            </div>
        )
    }
}